package oops.innerclasses;

public class ClassEnclosingAMethodWithANamedInnerClass {
	
	private int i = 0;
	private char ch = 'p';
	private String str = "ENCOSING-CLASS";
	
	public void foo(final int bar) {
		final int foosLocalVar = 100;
		
		class ANamedInnerClass {
			int j = 2;
			
			public void innerClassesFoo() {
				System.out.println("\n\nfoosLocalVar (Cannot change this final var): " + foosLocalVar);
				System.out.println("foo() > ANamedInnerClass > j: " + j);
				
				// Fields of class NEED NOT BE final
				// local variables/Parameters of methods MUST BE final. Cannot be updated.
				i = 2 + bar + foosLocalVar;
				ch = 'c';
				updateStr("ANamedINNERCLASSOfFOO");
				System.out.println("\n\nTriggering method on enclosing class...");
				printData();
			}
		}
		
		ANamedInnerClass anic = new ANamedInnerClass();
		anic.innerClassesFoo();
	}
	
	private void updateStr(String str) {
		this.str = str;
	}
	
	public void printData() {
		System.out.println("\n\nDATA: "
				+ "i = " + i
				+ "\tch = " + ch
				+ "\tstr = " + str
		);
	}

	public static void main(String[] args) {
		ClassEnclosingAMethodWithANamedInnerClass cl = new ClassEnclosingAMethodWithANamedInnerClass();
		cl.printData();
		
		cl.foo(999);
		
		cl.printData();
	}

}
